import {GameManager} from "db://assets/scripts/game/GameManager";
import {GameState} from "db://assets/scripts/game/GameState";
import {EventManager} from "db://assets/scripts/common/EventManager";
import {EventType} from "db://assets/scripts/common/EventType";

/**
 * 游戏状态代理
 */
export class GameStateProxy {
    /**
     * 游戏状态
     */
    private gameState: GameState = GameState.LOGGING;
    /**
     * 是否胜利
     */
    private win: boolean = false;

    /**
     * 代理对象
     */
    private proxy: GameManager;

    constructor(proxy: GameManager) {
        this.proxy = proxy;
    }

    /**
     * 设置游戏状态
     *
     * @param gameState 游戏状态
     */
    public setGameState(gameState: GameState) {
        this.gameState = gameState;
    }

    /**
     * 获取游戏状态
     */
    public getGameState(): GameState {
        return this.gameState;
    }

    /**
     * 设置游戏是否胜利
     *
     * @param win 游戏是否胜利
     */
    public setWin(win: boolean) {
        this.win = win;

        // 发送游戏结束事件
        if (this.gameState === GameState.PLAYING) {
            EventManager.dispatchEvent(EventType.ON_GAME_OVER);
        }
    }

    /**
     * 获取游戏是否胜利
     */
    public getWin(): boolean {
        return this.win;
    }
}